package com.qfedu.controller;

import com.alibaba.fastjson.JSON;
import com.qfedu.entity.Type;
import com.qfedu.service.TypeService;
import com.qfedu.service.impl.TypeServiceImpl;
import com.qfedu.utils.BaseServlet;
import com.qfedu.utils.Constants;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.sql.SQLException;
import java.util.List;

@WebServlet("/type.do")
public class TypeServlet extends BaseServlet {
    private TypeService typeService  = new TypeServiceImpl();
    public String getTypeList(HttpServletRequest request, HttpServletResponse response){
        try {
            List<Type> typeList = typeService.getAllType();
            return JSON.toJSONString(typeList);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        request.setAttribute("msg","服务器发生异常");
        return Constants.FORWARD + "/message.jsp";
    }
}
